package com.guo;

import org.junit.Test;

import java.text.DecimalFormat;
import java.util.*;
import java.util.function.Predicate;

/**
 * @author gonghuaiguo
 */
public class TestFileUtil {

    public static String getPath(){
        return "D:\\javaLearn\\springboot-learn\\guo-poi\\";
    }

    @Test
    public void testDemo1(){
//        System.out.println(Stream.of("green","yellow","blue")
//                .max((s1,s2)->s1.compareTo(s2))
//                .filter(s - toString().endsWith("n")).orElse("yellow"));

        String s1 ="new hello";
        String s2 = new String("new hello");
        s1.matches(s1);

        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add(0,"3");
        list.add(1,"4");
    }

    @Test
    public void testDemo02(){

        System.out.println("count= " +Parent.getCount());
        Son son = new Son();
        System.out.println("count = "+Parent.getCount());
    }

    @Test
    public void testDemo03(){
        List<String> letter = new ArrayList<>(Arrays.asList("D","B","A","C","F","G"));

        Predicate<String> p1 =s -> s.compareTo("C") > 0;
        Predicate<String> p2 =s -> s.equals("B");

        letter.removeIf(p1.negate().or(p2));

        letter.sort((s1,s2)->s1.compareTo(s2));
        System.out.println(letter);

    }
    static int x ;

    @Test
    public void testDemo04(){
        List<Person> people = Arrays.asList(new Person("Bob", 1), new Person(2), new Person("Jane", 3));
//         AtomicInteger x = new AtomicInteger();


        Optional<Person> reduce = people.stream().reduce((s1, s2) -> {
            x = s1.id;
            if (s1.id > s2.id) {
                return s1;
            } else {
                x = s2.id;
                return s2;
            }
        });
        System.out.println(reduce);
        Optional<String> s = reduce.flatMap(e -> Optional.ofNullable(e.name));
        System.out.println(s);


//                .flatMap(e -> Optional.ofNullable(e.name)).map(y -> new Person(y, x)).ifPresent(System.out::println);



    }

    @Test
    public void testDemo06(){
        double sss = 78943.5343;
        System.out.println(sss);
//        System.out.println(DecimalFormat.getInstance("00.0").format(sss));
        System.out.println(new DecimalFormat("0.0").format(sss));
    }

    @Test
    public void testDemo07(){
        Runnable r = () -> System.out.println("HI");
        new Thread(r).start();
    }
}

class Parent {
    static int count =0;

    public Parent() {
        count++;
    }
    static int getCount(){
        return count;
    }
}

class Son extends Parent{
    public Son() {
        count++;
    }
}

class MyCollection<T> {
    private Set<T> set;

    public Set<T> getCollection(){
        return set;
    }
}

class Person{

    public String name;
    public int id;

    public Person(int id){
        this.id = id;
        System.out.println("person1 类的初始化");
    }

    public Person(String name, int id) {
        System.out.println("Person 类初始化");
        this.name = name;
        this.id = id;
    }

    @Override
    public String toString() {
        return name +"  "+id;
    }


}